<?php 

/**
 * FreeY_Paginator
 *
 * @auther		FreeYadmin <FreeYadmin@gmail.com>
 * @update		none
 * @package		FreeY
 */	
class FreeY_Paginator
{
	/**
	 * var
	 */
	public $page = null;
	/**
	 * var
	 */
	public $count = null;
	/**
	 * var
	 */
	public $page_count = null;
	/**
	 * var
	 */
	public $size = null;
	/**
	 * var
	 */
	public $size_max = 1000000;
	/**
	 * _method
	 *
	 * @param $var
	 * @return viod
	 */
	public function __construct($count, $page, $size = 10)
	{
		$this->count = $count;
		$this->page = $page;
		$this->size = $size;
		$this->_setSize();
		$this->_setCount();
		$this->_setPageCount();
		$this->_setPage();
	}

	/**
	 * _method
	 *
	 * @param $var
	 * @return viod
	 */
	public function getPagePages()
	{
		$pages = array();
		if(($this->page_count < 10) || ($this->page < 6))
		{
			$i = ($this->page_count > 10) ? 10 : $this->page_count;
			$num = $i;
			while($i--)
			{
				$pages[] = $num - $i;
			}
		}
		else
		{
			$i = 10;
			$num = $this->page + 5;
			$num = ($num > $this->page_count) ? $this->page_count : $num;
			while($i--)
			{
				$pages[] = $num - $i;
			}
		}
		return $pages;
	}

	/**
	 * _setSize
	 *
	 * @param $var
	 * @return viod
	 */
	private function _setSize()
	{
		$this->size = intval($this->size);
		if($this->size < 1)
			$this->size = 1;
		if($this->size > $this->size_max)
			$this->page = $this->size_max;
	}

	/**
	 * _setCount
	 *
	 * @param $var
	 * @return viod
	 */
	private function _setCount()
	{
		$this->count = intval($this->count);
	}

	/**
	 * _setPageCount
	 *
	 * @param $var
	 * @return viod
	 */
	private function _setPageCount()
	{
		$this->page_count = ceil( $this->count / $this->size);
		$this->page_count = intval($this->page_count);
		if($this->page_count < 1)
			$this->page_count = 1;
	}

	/**
	 * _setPage
	 *
	 * @param $var
	 * @return viod
	 */
	private function _setPage()
	{
		$this->page = intval($this->page);
		if($this->page < 1)
			$this->page = 1;
		if($this->page_count < $this->page)
			$this->page = $this->page_count;
	}

	/**
	 * _setPageNext
	 *
	 * @param $var
	 * @return viod
	 */
	public function getNextPage()
	{
		if($this->page >= $this->page_count)
			return ;
		$page_next = $this->page + 1;

		return $page_next;
	}

	/**
	 * _setPageBack
	 *
	 * @param $var
	 * @return viod
	 */
	public function getBackPage()
	{
		if($this->page == 1) return ;
		$page_back = $this->page - 1;

		return $page_back;
	}

}//FreeY end**********
//file end--------------------------------------------------------->